package cn.wsalix.biz.repository;

import java.util.List;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import cn.anlaser.repository.CommonRepository;
import cn.wsalix.biz.entity.ImageFile;
import cn.wsalix.biz.entity.RelationImage;

public interface RelationImageRepository extends
		CommonRepository<RelationImage> {
	@Query("select img from RelationImage relaImg,ImageFile img where relaImg.imageFile.id=img.id and relaImg.fkId=:fkId and relaImg.category.id = :catId")
	public List<ImageFile> findByCatIdAndFkid(@Param("fkId") Long fkId,
			@Param("catId") Long catId);
	
	
	@Modifying(clearAutomatically = true)
	@Query("delete from RelationImage relaImg where relaImg.imageFile.id =:imageId")
	public void deleteByImageId(@Param("imageId") Long imageId);
	
	@Modifying(clearAutomatically = true)
	@Query("delete from RelationImage relaImg where relaImg.fkId=:fkId and relaImg.category.id = :catId")
	public void deleteByImgtypeAndFkid(@Param("fkId") Long fkId,@Param("catId") int catId);
}
